<?php

	class collocate_goods_listener extends pageFactory
	{
		function collocate_goods_listener()
		{
			parent::pageFactory();
			$this->system = &$GLOBALS['system'];
			$this->db = &$this->system->database();
		}

		function goodsSave($args,$data)
		{
			$pValue = $data['collocation'];
			$objGoods = $this->system->loadModel('trading/goods');
			//处理搭配商品
			foreach ($data['collocation']['name'] as $key => $name)
			{
				$aItem['name'] = $name;
				$aItem['type'] = $data['collocation']['type'][$key];
				$aItem['min_num'] = $data['collocation']['min_num'][$key];
				$aItem['max_num'] = $data['collocation']['max_num'][$key];
				$aItem['set_price'] = $data['collocation']['set_price'][$key];
				$aItem['price'] = $data['collocation']['price'][$key];
				$aItem['isBind'] = $data['collocation']['isBind'][$key];
				$aItem['isShowOriPrice'] = $data['collocation']['isShowOriPrice'][$key];
				$aItem['isShowSaving'] = $data['collocation']['isShowSaving'][$key];
				$aItem['items'] = $data['collocation']['items'][$key];
				$aCollacation[$key] = $aItem;
			}
			$objGoods->setGoodsMemo($data['goods_id'],'collocation',$aCollacation);
		}

		function orderCreate($args,$data)
		{
			//通过前台创建的订单 需要清空搭配商品规则
			$objCollocAddon = $this->system->loadModel('plugins/collocate_goods/collocAddon');
			list($ident,$ctl,$method) = explode(':',$this->system->request['action']['ident']);
			if ('shop' == $ident)
			{
				if ($data['member_id'])
				{
					$sql = 'UPDATE sdb_collocate_goods_collocaddon SET addon="" WHERE member_id='.$data['member_id'];
					$this->db->exec($sql);
				}
				else $this->system->setcookie($objCollocAddon->coCookie,'');
			}
		}
	}

?>